<!DOCTYPE html>
<html lang='zh-CN'>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>商品浏览规则</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <!--日期选择插件-->
    <link rel="stylesheet" href="js/bootstrap-datepicker/bootstrap-datepicker3.min.css">
    <!--修改图片-->
    <link rel="stylesheet" href="js/dropzone/min/basic.min.css" />
    <link rel="stylesheet" href="js/dropzone/min/dropzone.min.css" />
    <!--时间选择插件-->
    <link rel="stylesheet" href="js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css">


</head>
<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">

                    <div id="toolbar" class="toolbar-btn-action">
                        <form class="form-inline" method="post" id="searchForm">
                            <div class="form-group">
                                <label>店铺:</label>
                                <select name="shopId" class="form-control">
                                    <option value="">全部</option>
                                    <option value="0">烽鸟自营店</option>
                                    <option value="1">驿站</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-info btn_query btn-round" type="button" id="searchFormBtn">查询</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-success btn_query btn-round" type="button" id="addBtn">添加</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-warning btn_query btn-round" type="button" id="editBtn">编辑</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-danger btn_query btn-round" type="button" onclick="changeUserStatus(0)">未激活</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-purple btn_query btn-round" type="button" onclick="changeUserStatus(1)">激活</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-dark btn_query btn-round" type="button" id="shopInte">店铺上限规则</button>
                            </div>
                            <div class="form-group">
                                <button class="btn  btn-pink btn_query btn-round" type="button" id="relaProduct">关联商品</button>
                            </div>

                        </form>
                    </div>

                </div>
                <div class="card-body">

                    <table id="grid_data" class="table text-nowrap"></table>

                </div>
            </div>
        </div>
    </div>

    <!--  添加与编辑模态框 -->
    <div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <div id="error_tips" style="color: #c9302c"></div>
                </div>
                <div class="modal-body">
                    <form id="addOrEditForm"  method="post">
                        <div class="row">

                           <!-- <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon">店铺id</span>
                                    <input type="text" name="shopId" placeholder="0表示烽鸟自营店，1表示驿站" class="form-control" aria-describedby="basic-account"  id="shopId">
                                    <div class="help-block with-errors"></div>
                                </div>
                            </div>-->

                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon" id="shopId">店铺id</span>
                                    <select name="shopId" class="form-control">
                                        <option value="0">烽鸟自营店</option>
                                        <option value="1">驿站</option>
                                    </select>
                                </div>
                            </div>


                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon" id="basic-account">曝光次数</span>
                                    <input type="hidden" name="id">
                                    <input type="num" name="exposureCount"  class="form-control" aria-describedby="basic-account" onkeyup="value=(value.replace(/\D/g,'')==''?'':parseInt(value))" id="exposureCount">
                                    <div class="help-block with-errors"></div>
                                </div>
                            </div>


                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon">积&nbsp;&nbsp;分</span>
                                    <input type="num" name="exposureIntegral" class="form-control" aria-describedby="basic-account" onkeyup="value=(value.replace(/\D/g,'')==''?'':parseInt(value))"  id="exposureIntegral">
                                    <div class="help-block with-errors"></div>
                                </div>
                            </div>

                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon">浏览曝光时间</span>
                                    <input type="num" name="exposureCountdown" placeholder="秒单位" class="form-control" aria-describedby="basic-account" onkeyup="value=(value.replace(/\D/g,'')==''?'':parseInt(value))"  id="exposureCountdown">
                                    <div class="help-block with-errors"></div>
                                </div>
                            </div>

                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon">剩余次数</span>
                                    <input type="num" name="surplus"  class="form-control" aria-describedby="basic-account" onkeyup="value=(value.replace(/\D/g,'')==''?'':parseInt(value))" id="surplus">
                                    <div class="help-block with-errors"></div>
                                </div>
                            </div>
                        </div>
                    </form>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary addSaveBtn" id="addSaveBtn">保存</button>
                    </div>
                </div>

            </div>
        </div>
    </div>



    <!--  上限 -->
    <div class="modal fade" id="addOModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <div id="upperLimites" style="color: #c9302c"></div>
                </div>
                <div class="modal-body">
                    <form id="upperLimit"  method="post">
                        <div class="row">

                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon" >店铺id</span>
                                    <select name="id" id="id" onchange="selectOnchang(value)" class="form-control">
                                        <option value="">请选择店铺</option>
                                        <option value="0">烽鸟自营店</option>
                                        <option value="1">驿站</option>
                                    </select>
                                </div>
                            </div>



                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon">上限领取积分</span>
                                    <input type="num" name="integral" placeholder="积分" class="form-control" aria-describedby="basic-account" onkeyup="value=(value.replace(/\D/g,'')==''?'':parseInt(value))"  id="integral">
                                    <div class="help-block with-errors"></div>
                                </div>
                            </div>

                        </div>
                    </form>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary addSaveBtn" id="SaveBtn">保存</button>
                    </div>
                </div>

            </div>
        </div>
    </div>





    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
    <script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.message.js"></script>
    <!-- bootstrap表单验证插件 -->
    <script type="text/javascript" src="js/bootstrap-validator-master/dist/validator.js"></script>
    <!--es表格-->
    <script type="text/javascript" src="js/excel/jszip.min.js"></script>
    <script type="text/javascript" src="js/excel/FileSaver.js"></script>
    <script type="text/javascript" src="js/excel/excel-gen.js"></script>
    <!-- bootstrap表单验证插件 -->
    <script type="text/javascript" src="js/bootstrapvalidator/dist/js/bootstrapValidator.js"></script>
    <!-- jquery-form表单提交插件 -->
    <script type="text/javascript" src="js/jquery-form/jquery.form.js"></script>
    <!-- bootstrap弹出框插件 -->
    <script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
    <!-- 表单填充插件 -->
    <script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>
    <!-- 邮箱自动填充插件 -->
    <script type="text/javascript" src="js/email/autoMail.js"></script>
    <!-- boostrap-combox下拉框检索插件 -->
    <script type="text/javascript" src="js/suggest/bootstrap-suggest.min.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.suggest.js"></script>
    <!--日期选择插件-->
    <script src="js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
    <script src="js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
    <!-- 调用日期插件 -->
    <script type="text/javascript" src="js/main.min.js"></script>
    <script type="text/javascript" src="js/dropzone/min/dropzone.min.js"></script>
    <script src="js/bootstrap-datetimepicker/moment.min.js"></script>
    <script src="js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
    <script src="js/bootstrap-datetimepicker/locale/zh-cn.js"></script>

    <script type="text/javascript">


        //设置表头
        var columns = [
            {checkbox: true},
            {field: 'id',title: 'id'},
            {field: 'shopId',title: '店铺ID',formatter: function (value, row, index) {
                    if(value=='0') {
                        return "烽鸟自营店"
                    }else if(value=='1') {
                        return "驿站"
                    }
                }},
            {field: 'exposureCount',title: '曝光次数'},
            {field: 'exposureIntegral',title: '积分'},
            {field: 'exposureCountdown',title: '浏览时间'},
            {field: 'createTime',title: '操作时间'},
            {field: 'surplus',title: '剩余次数'},
            {field: 'ids',title: '商品ids'},
            {field: 'state',title: '状态',formatter: function (value, row, index) {
                    if(value=='0') {
                        var html= "<button class=\"btn btn-danger btn-sm\">未激活</button>";
                        return html
                    }else if(value=='1') {
                        var html= "<button class=\"btn btn-purple btn-sm\">激&nbsp;活</button>";
                        return html
                    }
            }}
        ];

        //进入主界面加载数据
        zero2one.datagrid("grid_data", "/remote/goodsBrowse/list",function (params) {
            return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchForm"));
        }, columns);

        //点击查询按钮重新加载页面数据
        $("#searchFormBtn").click(function () {
            $('#grid_data').bootstrapTable('refresh');
        });

        //关联商品
        $("#relaProduct").click(function () {

            var datas = $('#grid_data').bootstrapTable('getSelections');
            if(datas.length==1){
                console.log(datas[0].id);
                console.log(datas[0].shopId);
                window.location.href= "/goosBrowsePlus.html?ruleId="+datas[0].id+'&businessId='+datas[0].shopId;
            }else {
                $.messager.alert("请选择一条数据");
            }
        });

        //改变状态
        function changeUserStatus(statues) {
            //获取选中行的数据
            var datas = $('#grid_data').bootstrapTable('getSelections');
            //判断是否选中行数据，如果没有则提示
            var vo={"statues" : statues,"ids" : zero2one.array2str(datas)};
            if(datas.length > 0){
                $.messager.confirm("温馨提示", "您确定更改状态吗?", function () {
                    $.ajax({
                        url: '/remote/goodsBrowse/updateByIds',
                        contentType:'application/json',
                        type: 'post',
                        data: JSON.stringify(vo),
                        dataType: 'json',
                        success: function (res) {
                            if (res.success){
                                $.messager.alert("温馨提示", "操作成功,2S之后刷新");
                                setTimeout(function () {
                                    window.location.reload();
                                }, 2000);
                            }else {
                                $.messager.alert("温馨提示","操作失败");
                            }
                        }
                    });

                })
            }else{
                $.messager.alert("温馨提示", "请至少选择一条数据操作");

            }
        }

        //添加
        $("#addBtn").click(function () {

            $('#addOrEditForm')[0].reset();
            $("#addOrEditModal").modal("show");

        });

        //编辑用户
        $("#editBtn").click(function () {
            //获取选中行的数据
            var datas = $('#grid_data').bootstrapTable('getSelections');
            if(datas.length == 1){
                $("#addOrEditForm").formloader({data: datas[0]});
                $("#exposureCount").val(datas[0].exposureCount);
                $("#exposureIntegral").val(datas[0].exposureIntegral);
                $("#exposureCountdown").val(datas[0].exposureCountdown);
                $("#surplus").val(datas[0].surplus);
                $("#addOrEditModal").modal("show");
            }else{
                $.messager.alert("温馨提示", "请选择一条数据操作");
            }
        });

        $('#addOrEditForm').bootstrapValidator({
            fields: {
                shopId: {validators: {notEmpty: {message: '店铺id不能为空'}}},
                exposureCount: {validators: {notEmpty : {message: '曝光次数不能为空'}}},
                exposureIntegral: {validators: {notEmpty : {message: '积分不能为空'}}},
                exposureCountdown: {validators: {notEmpty : {message: '浏览时间不能为空'}}},
            }
        });


        //点击保存按钮
        $("#addSaveBtn").click(function () {
            var bv = $('#addOrEditForm').data('bootstrapValidator');
            bv.validate();
            if (bv.isValid()) {
                zero2one.request("/remote/goodsBrowse/addOrEditRule",$("#addOrEditForm").serialize(),function (data) {
                    window.location.reload();
                });
            }
        });

        function selectOnchang(obj){

            var vo={"idInte":obj};
            $.ajax({
                url: '/remote/goodsBrowse/integral',
                contentType:'application/json',
                type: 'post',
                data: JSON.stringify(vo),
                dataType: 'json',
                success: function (res) {
                    if (res.success){
                        $("#integral").val(res.data)
                    }else {
                        $.messager.alert("温馨提示","操作失败");
                    }
                }
            });

        }

        //上限
        $("#shopInte").click(function () {

            $("#addOModal").modal("show");
        });

        //点击保存按钮
        $("#SaveBtn").click(function () {

           var id=$("#id").val();
          var integral=$("#integral").val();
            $.messager.confirm("温馨提示", "您确定更改上限积分吗?", function () {

                var vo={"integral":integral,"id":id};
                $.ajax({
                    url: '/remote/goodsBrowse/updateByIn',
                    contentType:'application/json',
                    type: 'post',
                    data: JSON.stringify(vo),
                    dataType: 'json',
                    success: function (res) {
                        if (res.success){
                            window.location.reload();
                        }else {
                            $.messager.alert("温馨提示","操作失败");
                        }
                    }
                });

            })

        });




    </script>

</div>
</body>
</html>
